package Bestellung;

import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.DefaultListModel;

import Einkaufer.KomponentenList;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

public class BestellKomponentenList {

	private int id;
	private DefaultListModel dlm;
	int anzahl;
	Connection connection;
	
	public BestellKomponentenList(int id, int anzahl, DefaultListModel dlm, Connection connection) {

		this.id = id;
		this.dlm = dlm;
		this.anzahl = anzahl;
		this.connection = connection;
		
	}
	
	public DefaultListModel getKonfiguration() throws SQLException {
		
		
		ResultSet rs;
        Statement st = (Statement) connection.createStatement();
        rs = st.executeQuery("SELECT konfiguration.kid, konfiguration.kind, vehiclepart.name  FROM konfiguration JOIN vehiclepart ON konfiguration.vpid = vehiclepart.vpid WHERE konfiguration.kid ="+this.id);
        
        while (rs.next()) {
            String kind = rs.getString("kind");
            String vpname = rs.getString("name");
            
            String res = anzahl+"x "+vpname+": "+kind;
            
            dlm.addElement(new KomponentenList(res));
            
           
        }
			
		
		return dlm;	
		
	}

}
